package com.wtwd.campus.send;

import com.alibaba.fastjson.JSONArray;
import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.Command;
import com.wtwd.campus.entity.MqMessage;
import com.wtwd.campus.entity.MqSetAllWhiteCall;
import com.wtwd.campus.utils.UnicodeUtil;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class SetAllWhiterListNumberSender implements Sender {
    @Override
    public Command dealMessage(MqMessage mqMessage) {
        MqSetAllWhiteCall mqSetAllWhiteCall = (MqSetAllWhiteCall)mqMessage.getObject();
        String imei = mqSetAllWhiteCall.getImei();
        String commandNumber = mqSetAllWhiteCall.getCommandNumber();
        List<Map<String, Object>> whiteCallList = mqSetAllWhiteCall.getWhiteCallList();
        String cmd = mqMessage.getType();
        String whiteCallContent = "";
        for(Map<String,Object> whiteCall : whiteCallList){
            String name = (String)whiteCall.get("name");
            String phone = (String)whiteCall.get("phone");
            String sequence = String.valueOf(whiteCall.get("sequence"));
            String parseName = UnicodeUtil.gbEncoding(name);
            // type 默认为1，pic默认为1，imeid为0
            whiteCallContent = whiteCallContent.concat(",").concat(sequence).concat(",").concat(phone).concat(",1,0,").concat(parseName).concat(",1,");
        }
        String content = "*".concat(Constants.MANUFACTURER_NAME).concat(",").concat(imei).concat(",").concat(cmd).concat(",").concat(commandNumber)
                .concat(whiteCallContent).concat("#");
        Command command = new Command();
        command.setImei(imei);
        command.setContent(content);
        command.setCmd(cmd);
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        command.setCommandNumber(commandNumber);
        return command;
    }
}
